<!--
File Upload Meter - DEMO and API
http://abhinavsingh.com/webdemos/fileuploadmeter/fileuploadmeter.rar
http://abhinavsingh.com/blog/2008/08/how-to-create-an-upload-meter-in-php-explained/
Developer : Abhinav Singh
Contact : admin@abhinavsingh.com
Date : 29th August, 2008

NOTE: Kindly keep this part of the code untouched if you are using or copying the code from here. 
Thanks in advance,
Abhinav
-->
<?php

  if((isset($_POST['uploadfile'])) && ($_POST['uploadfile'] == "uploadfile")) {
    
    // Gather File data (name,size,mimetype,tmp_name)
    $FileName = $_FILES['fileloc']['name'];
    $FileSize = round($_FILES['fileloc']['size']/1024);
    $FileType = $_FILES['fileloc']['type'];
    $FileTemp = $_FILES['fileloc']['tmp_name'];
    
    
    // Get file extension
    $extension = strtolower(substr($FileName,strrpos($FileName,'.')+1));
    
    // If filename is blank, exit with a message
    if($FileName == "") {
      echo "<script type='text/javascript'>";
      echo "parent.document.getElementById('upload-note').innerHTML = '<font size=2 color=#990000>Kindly choose a file to upload</font>'";
      echo "</script>";
      exit;
    }
    
    // If filesize is > 10 Mb, exit with a message
    if($FileSize >= "10240") {
      echo "<script type='text/javascript'>";
      echo "parent.document.getElementById('upload-note').innerHTML = '<font size=2 color=#990000>OOPS! The file exceeds the maximum limit of 10 Mb</font>'";
      echo "</script>";
      exit;
    }
    
    // Exit if file's extension is not .mp3
    /*if($extension != "mp3") {
      echo "<script type='text/javascript'>";
      echo "parent.document.getElementById('upload-note').innerHTML = '<font size=2 color=#990000>OOPS! Only mp3 file formats are supported</font>'";
      echo "</script>";
      exit;
    }*/
    
    // Choose a final upload location
    $FileUploadLocation = "upload/".$FileName.".".strtolower($extension);
    
    // Invoke the progress script
    echo "<script type='text/javascript'>";
    echo "parent.getProgress()";
    echo "</script>";
    
    // Move the uploaded file from temp to final upload location
    if(move_uploaded_file($FileTemp,$FileUploadLocation)) {
      echo "<script type='text/javascript'>";
      echo "parent.document.getElementById('upload-note').style.display='none';";
      echo "parent.document.getElementById('attachment').innerHTML = '<input CHECKED type=\"checkbox\"><font color=#003399 size=2><b>".$FileName."</b> (".$FileType.") ".$FileSize." Kb</font>';";
      echo "</script>";
    }
    else {
      echo "<script type='text/javascript'>";
      echo "parent.document.getElementById('upload-note').innerHTML = '<font size=2 color=#990000>OOPS! An error occurred, please try again</font>'";
      echo "</script>";
    }
    
  }
  
?>
